/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Test;

import SecureUtil.PBEHelper;
import java.util.Arrays;
import javax.crypto.SecretKey;

/**
 *
 * @author agener
 */
public class TestPBEHelper {
    public static void main(String[] argv){
        try{
        String password = "HelloWorld";
        String salt = PBEHelper.generateSalt();
        String pwhash = PBEHelper.getPasswordHash("HelloWorld");
        String testString  = "sadfasdfasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafasdfasdfasdfasdadfasdfasdfasdfsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasdfasdfasdfasdfasdfasdf" ;
		
        System.out.println("salt: "+salt);
        System.out.println("password hash: "+pwhash);
        SecretKey pswKey = PBEHelper.getPBEKey(pwhash, salt);
        System.out.println("before encrypt: " + testString);
        byte[] encrypted = PBEHelper.PBEencrypt(pswKey, testString.getBytes());
        System.out.println("after encrypt: "+new String(encrypted));
        byte[] decrypted = PBEHelper.PBEdecrypt(pswKey, encrypted);
        System.out.println("after decrypt: " + new String(decrypted));
        if(Arrays.equals(testString.getBytes(), decrypted)){
            System.out.println("byte[] equals");
        }
        if(testString.equals(new String(decrypted))){
            System.out.println("String equals");
        }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
